package com.yuexunit.finance.project.service;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.project.entity.FinanceCutLinesEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.persist.annotation.Transactional;


/**
 * @author wenwenlong
 */
@Implements(FinanceCutLinesService.class)
public class FinanceCutLinesServiceImpl implements FinanceCutLinesService {

	@Override
	@Transactional
	public Long createFinanceCutLines(FinanceCutLinesEntity entity) {
		PersistUtil.insert(entity);
		return entity.getCutId();
	}

	@Override
	@Transactional
	public void updateFinanceCutLines(FinanceCutLinesEntity entity) {
		PersistUtil.update(entity);
	}

	@Override
	public FinanceCutLinesEntity inquireFinanceCutLines(Long cutId) {
		return PersistUtil.get(FinanceCutLinesEntity.class, cutId);
	}

	@Override
	public PageList<FinanceCutLinesEntity> inquireFinanceCutLinesPageList(Long financeId, PageCriteria page) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceCutLinesEntity.class);
		if (financeId != null) {
			criteria.add(Restrictions.eq("financeId", financeId));
		}
		criteria.addOrder(Order.desc("createDateTime"));
		return PersistUtil.get(criteria, page);
	}

}
